class WS {
    constructor() {
        this.ws = null;
        this.connect();
        this.onopen();
        this.onclose();
        this.onerror();
    }

    connect() {
        this.ws = new WebSocket("ws://192.168.4.1:81");
        console.log("this.ws: ", this.ws);
    }

    onopen() {
        this.ws.onopen = () => {
            console.log("WebSocket open");
        }
    }

    onmessage(callback) {
        this.ws.onmessage = (e) => {
           callback(e.data)
        }
    }

    onclose() {
        this.ws.onclose = (e) => {
            console.log("close");
        }
    }

    onerror() {
        this.ws.onerror = (e) => {
            console.log("onerror");
        }
    }
}